package net.zjitc.listthree.web;

import net.zjitc.listthree.domin.User;
import net.zjitc.listthree.service.UserService;
import net.zjitc.listthree.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author Administrator
 * @Date 2020/6/18 16:45
 * 表示层的控制器Servlet
 * 作用：
 * 1.获取请求参数
 * 2.需要的话，将参数封装
 * 3.调用service层相应方法完成功能（可能需要传递参数）
 * 4.需要的话，将结果保存在域对象（供视图jsp展示数据）
 * 5.转发或重定向到另一个Jsp/servlet
 **/
@WebServlet("/userList")
public class UserList extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*1.调用service层相关方法完成列表查询功能，得到结果List<User>*/
        UserService service=new UserServiceImpl();
        List<User> userList=service.findAll();
        request.setAttribute("userList",userList);
        request.getRequestDispatcher("/listthree/list.jsp").forward(request,response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
